package learning.groovy.collection

class RangeDemo {
	static main(args){
		println ((0..10).contains(0))
		println ((0..10).contains(-1))
		println (0..<10)

		def a = 0..10
		println a instanceof Range
		
		a = new IntRange(0,10)
		println a.contains(5)
		
		println ((0.0..1.0).contains(0.5))
		println ((0.0..1.0).contains(1.0))

		def today = new Date()
		def yesterday = today - 1
		println ((yesterday..today).size())
		
		println (('a'..'c').contains('b'))
		
		def log = ''
		for(element in 5..9){
			log += element
		}
		println log
		
		log = ''
		for(element in 9..5){
			log += element
		}
		println log
		
		log = ''
		(9..<5).each {element ->
			log += element
		}
		println log
		
		def result = ''
		(5..9).each {element ->
			result += element
		}
		println "result:" + result
		
		println ((0..10).isCase(5))
		
		def age = 36
		switch(age){
			case 16..20 : println '16..20'; break
			case 21..50 : println '21..50'; break
			case 51..65 : println '51..65'; break
			default: throw new IllegalArgumentException()
		}
		
		def ages = [20, 36, 42, 56]
		def midage = 21..50
		println ages.grep(midage)
		println ages.grep(midage) == [36, 42]
		
	}
}
